#include "calculate.h"
#include <iostream>

int judge()
{       
    int c;
    std::cin >> c;
    return c;
}


int calculate(char ch, int a, int *b)
{
    switch (ch)
    {
    case '+':
        return add(a, *b);
        break;

    case '-':
        return subtraction(a, *b);
        break;

    case '*':
        return multiplication(a, *b);
        break;
    
    case '/':
        while(*b == 0)
        {
            std::cout << "The dividend can not be 0, please input the dividend again" << std::endl;
            *b = judge();
        }
        return division(a, *b);
        break;

    case '%':
        while (*b == 0)
        {
            std::cout << "The dividend can not be 0, please input the dividend again" << std::endl;
            *b = judge();
        }
        return surplus(a, *b);

    default:
    return 0;
        break;
    }
}

void user()
{
    char ch;
    int a;
    int b;
    std::cout << "Please select an operation:"  << std::endl;
    std::cout << "+" << std::endl;
    std::cout << "-" << std::endl;
    std::cout << "*" << std::endl;
    std::cout << "/" << std::endl;
    std::cout << "%" << std::endl;

    std::cin >> ch;

    std::cout << "Please input two integers:" << std::endl;
    
    std::cin >> a >> b;
    int ans = calculate(ch, a, &b);
    std::cout << a << ch << b << "=" << ans << std::endl;
}